package com.hankol.community

import android.webkit.JavascriptInterface
import com.alibaba.android.arouter.facade.annotation.Route
import com.baselibrary.activity.BaseActivity
import com.baselibrary.extension.checkNotNull
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.ARouterUtils.parseParams
import com.baselibrary.utils.MyJavascriptInterface
import com.baselibrary.view.ArticleWebViewClient
import com.hankol.community.databinding.ActivityTopicContentDetailBinding


/**
 *@author:hanke
 *2022/4/6
 *desc:话题内容详情页
 */
@Route(path = ActivityRouter.COMMUNITY.COMMUNITY_TOPIC_CONTENT_DETAIL)
class TopicContentDetailActivity : BaseActivity() {
    private var contentDetail = ""
    private var title = ""
    private lateinit var mDataBinding: ActivityTopicContentDetailBinding
    override fun getLayoutId(): Int {
        return R.layout.activity_topic_content_detail
    }

    override fun init() {
        mDataBinding = getDataBinding<ActivityTopicContentDetailBinding>()
        initWebView()
    }
    private fun initWebView() {
        if (intent.extras.checkNotNull()) {
            title = parseParams(intent.extras!!, "title")[0].toString()
            contentDetail = parseParams(intent.extras!!, "content")[0].toString()
        }
        mDataBinding.tvTopicContentTop.text="$title"
        mDataBinding.wbTopicContentDetail.webViewClient = ArticleWebViewClient()
        mDataBinding.wbTopicContentDetail.addJavascriptInterface(object : MyJavascriptInterface {
            @JavascriptInterface
            fun imgClick(data: String?) {
            }
        }, "injectedObject")
        mDataBinding.wbTopicContentDetail.loadData(contentDetail, "text/html; charset=UTF-8", "UTF-8")

        mDataBinding.ivTopicContentDetailBack.setOnClickListener { finish() }
    }
}